package com.jyw.business.obstacles.domain.vo.web;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.jyw.business.obstacles.domain.ObsOrderAssist;
import com.jyw.business.obstacles.domain.ObsOrderFault;
import com.jyw.common.annotation.Conversion;
import com.jyw.common.annotation.Excel;
import com.jyw.common.core.domain.entity.SysUser;
import com.jyw.common.enums.ConversionType;
import com.jyw.system.domain.vo.SimpleFileVo;
import com.jyw.system.utils.FileUtils;
import com.jyw.system.utils.UserUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.util.ObjectUtils;

import java.util.Date;
import java.util.List;

/**
 * @author 沈峻
 * @ClassName AssistMainDetailVO
 * @Description 工单详情-协作工单信息
 * @Date 2023/9/7 11:11
 **/
@ApiModel("工单详情-协作工单信息")
@Data
public class AssistMainDetailVO {

    /** 协作说明 */
    @ApiModelProperty("协作说明")
    @Excel(name = "协作说明")
    private String assistRemark;

    @ApiModelProperty("发起时间")
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date createTime;

    /** 协作发起人 */
    @ApiModelProperty("协作发起人")
    @Excel(name = "协作发起人")
    @Conversion(value = ConversionType.USER,name = AssistMainVO.Fields.createUserName)
    private Long createUser;

    @ApiModelProperty("协作发起人名称")
    private String createUserName;

    @ApiModelProperty("协作发起人电话")
    private String createUserPhone;

    @ApiModelProperty("公共附件")
    private List<SimpleFileVo> commonFile;

    @ApiModelProperty("协作事务")
    private String assistContent;

    @ApiModelProperty("协作附件")
    private List<SimpleFileVo> assistEnclosureList;

    public AssistMainDetailVO(ObsOrderAssist data, ObsOrderFault fault) {
        setAssistRemark(data.getAssistRemark());
        setCreateTime(data.getCreateTime());
        setCreateUser(data.getCreateUser());
        setCommonFile(FileUtils.IdToFile(data.getAssistEnclosureId()));
        SysUser user = UserUtils.getUserById(getCreateUser());
        if(!ObjectUtils.isEmpty(user)){
            setCreateUserPhone(user.getPhonenumber());
        }
        setAssistContent(fault.getAssistContent());
        setAssistEnclosureList(FileUtils.IdToFile(fault.getAssistEnclosureId()));
    }
}
